package com.third.device.mg.serialport.factory.lemanli

/**
 * @Date 2022/1/20
 * Description:
 */
abstract class BaseLeManLiProduct {

    companion object {
        /**控制指令*/
        const val TYPE_CONTROL_COMMAND = 0x0a

        /**指定运行位置*/
        const val TYPE_RUN_LOCATION = 0xdd

        /**参数/功能设定*/
        const val TYPE_SETTING_PARAMS = 0xd5

        /**状态查询*/
        const val TYPE_QUERY_STATE = 0xcc

        /**设置ID与频道*/
        const val TYPE_SETTING_ID = 0xaa

        /**删所有ID/频道*/
        const val TYPE_DELETE_ID = 0xa6

        /**设定最高转速*/
        const val TYPE_SETTING_RPM = 0xd9

        /**设定限位点*/
        const val TYPE_SETTING_POINT = 0xda



        //上行
        const val ACTION_UP = 0xDD
        //停止
        const val ACTION_STOP = 0xCC
        //下行
        const val ACTION_DOWN = 0xEE
        //学码
        const val ACTION_STUDY_CODE = 0xAA
        //删码
        const val ACTION_DELETE_CODE = 0xA6

    }

    /**
     * 产品描述
     */
    abstract fun productDescribe(): String


    /**
     * 指令增加校验码
     */
    fun commandCheckout(pushMsg: ByteArray): ByteArray {
        val code = LeManLiCRC.crcXor(pushMsg);
        val command = ByteArray(pushMsg.size + 1)
        System.arraycopy(pushMsg, 0, command, 0, pushMsg.size)
        command[command.size - 1] = code
        return command
    }
}